const install = function (Vue, opts = {}) {
  const sessionStorage = {};

  Vue.mixin({
    computed: {
      $isDev() {
        return BUILD_MODE !== "production" && BUILD_MODE !== "beta";
      },
      // 手机微站
      $mobileUrl() {
        if (BUILD_MODE == "production") return "https://mobile.medmeeting.com/#/";
        if (BUILD_MODE == "beta") return "https://mobilebeta.medmeeting.com/#/";
        return "https://mobiletest.medmeeting.com/#/";
      },
      $Toolbar() {
        return `formatselect | fontsizeselect | forecolor backcolor | bold | image | alignleft aligncenter alignright `;
      },
      $share_logo() {
        return "https://store-pics.medmeeting.com/rMLMyAoZ8DjpQY24h6kyWoQw3pG9AWBw_1655976947118";
      },
      // web直播
      $webLiveUrl() {
        if (BUILD_MODE == "production") return "https://www.medmeeting.com/#/weblive/login";
        if (BUILD_MODE == "beta") return "";
        return "https://website.medmeeting.com/#/weblive/login";
      },
      $site() {
        if (BUILD_MODE == "production") return "https://site.medmeeting.com/#/";
        if (BUILD_MODE == "beta") return "https://mobilebeta.medmeeting.com/#/";
        return "https://sitetest.medmeeting.com/#/";
      },
    },
    methods: {
      $isShangYao(id) {
        if (BUILD_MODE == "production") return id == "14";
        return id == "25";
      },
      $isShangYaoRoom(id) {
        if (BUILD_MODE == "production") return id == "109192";
        return id == "108647";
      },
      isAccount5C() {
        const userName = this.$store.state.user.userName;
        return ["Judyyu@healife.com", "Judy@healife.com"].includes(userName);
      },
      $setSessionStorage(key, value) {
        sessionStorage[key] = value;
      },
      $getSessionStorage(key) {
        return sessionStorage[key];
      },
      $clearSessionStorage(key) {
        sessionStorage[key] = null;
      },

      $tabList(filter = () => true) {
        const { meta, params } = this.$route;
        const list = meta.parentChildren.filter(filter).map((item) => {
          const url = item.path.replaceAll(/:(\w+)/g, (...args) => params[args[1]]);
          return {
            name: item.meta.title,
            url,
          };
        });

        return list;
      },
      $paramsFormat(v) {
        const params = { ...v };
        for (let key in params) {
          if (params[key] === "" || typeof params[key] === "undefined") {
            params[key] = null;
          }
        }

        return params;
      },
      $paramsPithy(v) {
        const result = {};
        for (const key in v) {
          if (v[key]) {
            result[key] = v[key];
          }
        }

        return result;
      },
      // 获取文件后缀类型
      $getFileExtname(url) {
        if (/(doc|docx)$/i.test(url)) return "WORD";
        if (/(ppt|pptx)$/i.test(url)) return "PPT";
        if (/\.xls/i.test(url)) return "EXCEL";
        if (/(pdf)$/i.test(url)) return "PDF";
        return "";
      },

      /**
       * @description: 合并数据
       * @param {*} origin 原始数据
       * @param {*} data 新数据
       * @return {*}
       */
      $mergeValueableData(origin, data) {
        for (const key in origin) {
          if (key in data) {
            origin[key] = data[key];
          }
        }

        return origin;
      },

      $formatUrl2https(url) {
        if (!url) return "";
        return url.slice(0, 5) == "http:" ? "https:" + url.slice(5) : url;
      },
    },
    filters: {
      $filterVoid(v) {
        return v || "--";
      },
      // 菜单题目名称
      $filterTitle(item) {
        return item.name || (item.meta && item.meta.title) || "占位符";
      },

      $FormatDate(v) {
        return Vue.prototype.$FormatDate("yyyy-MM-dd hh:mm:ss", v);
      },
      $FormatDateDay(v) {
        return Vue.prototype.$FormatDate("yyyy-MM-dd", v);
      },
    },
  });
};

export default {
  install,
};
